package com.gyc.simple.sysuser.controller;

import com.alibaba.fastjson.JSONObject;
import com.gyc.simple.common.util.JwtUtils;
import com.gyc.simple.common.vo.ResponseType;
import com.gyc.simple.common.vo.User;
import com.gyc.simple.sysuser.entity.base.ISource;
import com.gyc.simple.sysuser.service.SysResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * @program: Inaction
 * @description:
 * @author: Mr.gyc
 * @create: 2019-08-29 20:37
 */
@RestController
@RequestMapping("/sys/source/")
public class ISourceController {

    @Autowired
    private SysResourceService sysResourceService;

    @GetMapping("/getSourceList")
    public String getSourceList(@RequestParam Map paraMap){
        try {
            /*Optional.ofNullable(paraMap).ifPresent(val -> {
                paraMap.put("pageNum", Optional.ofNullable(paraMap.get("pageNum")).orElse(1));
                paraMap.put("pageSize", Optional.ofNullable(paraMap.get("pageSize")).orElse(7));
            });*/
            return Optional.ofNullable(JSONObject.toJSONString(sysResourceService.queryListByPageCondition(CommonMethod.checkPageParam(paraMap)))).orElse("");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    @GetMapping("/getCurUserSource")
    public ResponseType getCurUserSource(){
        User user = JwtUtils.JwtToUser();
        ResponseType responseType = new ResponseType();
        try {
            List<ISource> iSources = sysResourceService.selectByUID(user.getIuId());
            responseType.setStatus(true);
            responseType.setData(JSONObject.toJSON(iSources));
            return responseType;
        }catch (Exception e){
            e.printStackTrace();
        }
        return responseType;
    }

}
